//
//  HomePageCell1.m
//  Mtime2.0
//
//  Created by 凉气的Mac on 16/9/3.
//  Copyright © 2016年 凉气的Mac. All rights reserved.
//

#import "HomePageCell1.h"

#import "MtimeButton.h"

#import "MoveCell.h"

@interface HomePageCell1 ()<UICollectionViewDataSource>

@property(nonatomic,weak) UICollectionView *collectionView;

@end

@implementation HomePageCell1

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setupUI];
        
    }
    
    
    return self;
}

#pragma mark --
#pragma mark --设置界面
-(void)setupUI{

    [self setupTop];
    [self setupCollectionView];
    [self setupBottom];
}

#pragma mark --
#pragma mark --设置上方界面
-(void)setupTop{
    
    UILabel *sellTicketLable = [[UILabel alloc]init];
    
    sellTicketLable.text = @"正在上映";
    
    [self.contentView addSubview:sellTicketLable];
    
    [sellTicketLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(10);
        
        make.top.equalTo(self.contentView).offset(10);
        
        make.height.equalTo(@20);
        
    }];
    
    //城市按钮
    MtimeButton *cityBtn = [[MtimeButton alloc]init];
    
    [self.contentView addSubview:cityBtn];
    
    [cityBtn setTitle:@"上海" forState:UIControlStateNormal];
    
    [cityBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [cityBtn setImage:[UIImage imageNamed:@"homepage_selectcity"] forState:UIControlStateNormal];
    
    [cityBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(12);
        
        make.left.equalTo(sellTicketLable.mas_right).offset(15);
        
        make.height.equalTo(@15);
        
    }];
    
    //影片数量按钮
    MtimeButton *moveCountBtn = [[MtimeButton alloc]init];
    
    [self.contentView addSubview:moveCountBtn];
    
    [moveCountBtn setTitle:@"共51部" forState:UIControlStateNormal];
    
    [moveCountBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    
    [moveCountBtn setImage:[UIImage imageNamed:@"homePage_poster_jiantou"] forState:UIControlStateNormal];
    
    [moveCountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(12);
        
        make.right.equalTo(self.contentView.mas_right).offset(-15);
        
        make.height.equalTo(@15);
        
    }];
    
    
    
}

#pragma mark --
#pragma mark --设置collectionView
-(void)setupCollectionView{
    
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];

    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flow];
    
    collectionView.backgroundColor = [UIColor whiteColor];
    
    collectionView.dataSource = self;
    
    collectionView.showsHorizontalScrollIndicator = NO;
    
    collectionView.bounces = NO;
    
    [collectionView registerNib:[UINib nibWithNibName:@"MoveCell" bundle:nil] forCellWithReuseIdentifier:@"move"];
    
    flow.itemSize = CGSizeMake(80, 180);
    
    flow.minimumLineSpacing = 10;
    
    flow.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
    
    flow.minimumInteritemSpacing = 10;
    
    flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;

    self.collectionView = collectionView;
    
    [self.contentView addSubview:collectionView];
    
    [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.width.equalTo(self.contentView);
        
        make.height.equalTo(@180);
        
        make.top.equalTo(self.contentView).offset(50);
        
        make.bottom.equalTo(self.contentView).offset(-50);
        
    }];
    
    //线
    UIView *lineView = [[UIView alloc]init];
     
     lineView.backgroundColor = [UIColor colorWithWhite:0.800 alpha:1.000];
     
     [self.contentView addSubview:lineView];
     
     [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.equalTo(self.contentView);
        
        make.height.equalTo(@0.5);
        
        make.left.equalTo(self.contentView).offset(10);
    
        make.top.equalTo(self.collectionView.mas_bottom);
        
    }];

    

}

#pragma mark --
#pragma mark --下方界面
-(void)setupBottom{

    [self addTitleViewWithLableTitle:@"即将上映" btnTitle:@"53部" leftMargin:10];
    
    [self addTitleViewWithLableTitle:@"同城影院" btnTitle:@"204家" leftMargin:220];
    
    //线
    UIView *lineView = [[UIView alloc]init];
    
    lineView.backgroundColor = [UIColor colorWithWhite:0.800 alpha:1.000];
    
    [self.contentView addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.equalTo(@0.5);
        
        make.height.equalTo(@20);
        
        make.centerX.equalTo(self.contentView);
        
        make.top.equalTo(self.collectionView.mas_bottom).offset(17.5);
        
    }];
    
    
}


-(void)addTitleViewWithLableTitle:(NSString *)lableTitle btnTitle:(NSString *)btnTitle leftMargin:(CGFloat)leftMargin{

    UILabel *sellTicketLable = [[UILabel alloc]init];
    
    sellTicketLable.text = lableTitle;
    
    [self.contentView addSubview:sellTicketLable];
    
    [sellTicketLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(leftMargin);
        
        make.top.equalTo(self.collectionView.mas_bottom).offset(15);
        
        make.height.equalTo(@20);
        
    }];
    
    //城市按钮
    MtimeButton *cityBtn = [[MtimeButton alloc]init];
    
    [self.contentView addSubview:cityBtn];
    
    [cityBtn setTitle:btnTitle forState:UIControlStateNormal];
    
    [cityBtn setTitleColor:[UIColor colorWithWhite:0.800 alpha:1.000] forState:UIControlStateNormal];
    
    [cityBtn setImage:[UIImage imageNamed:@"homePage_poster_jiantou"] forState:UIControlStateNormal];
    
    [cityBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.collectionView.mas_bottom).offset(17);
        
        make.left.equalTo(sellTicketLable.mas_right).offset(15);
        
        make.height.equalTo(@15);
        
    }];


}


#pragma mark --
#pragma mark --collectionViewDataSoure
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 10;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    MoveCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"move" forIndexPath:indexPath];
    
    return cell;
    
}




@end




























































